package entity;

import map.Map;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;

import animation.MacAnimation;
import constans.ResourceManager;

import frame.Frame;

public class HerosCannon extends Cannon{

	
	
	public HerosCannon(Vector2f position) {
		super(position);
		animation = new MacAnimation(ResourceManager.getImage("cannon2"), 100, size);
		shootSnd = ResourceManager.getSound("heroShoot");
		// TODO Auto-generated constructor stub
	}
	
	public void update(GameContainer container, int delta) throws SlickException
	{		
		Input input = container.getInput();	
		Vector2f mousePosition = new Vector2f(input.getMouseX(), input.getMouseY());
		super.update(container, delta);
		direction = new Vector2f(mousePosition).add(Map.shift);
		direction.sub(position).normalise();
		animation.setDirection(direction);
		
		if(canShoot())
			if(input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON))
				if(!Frame.isOn(mousePosition))
				{	
					shoot(direction, true);
					animate = true;
					canAttack = false;
					shootSnd.play();
				}
	}

}
